// manager/pages/performancereporting/index.js
import { request } from '../../../utils/request';
import util from '../../../common/util';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {},
        activeIndex: 0,
		tabList: [
            { id: 1, text: "业绩填报" },
            { id: 2, text: "填报记录" },
            // { id: 3, text: "业绩分析" },
        ],
        perBusiList: [],
        // cardBusiList: [],
        pubBusiList: [],	
        othBusiList: [],
        
        params: {
            busiType: "1",    // 业务填报分类：1-个人类，2-绑卡类，3-对公类，4-其他业务
            busiName: "",    // 业务名称
            startDate: "",
            endDate: "",
        },
        dict: {},
        typeIndex: 0,
        list: []
        // scroller: {
		// 	pageNum: 0,
		// 	pageSize: 10,
		// 	totalPage: 10,
		// 	isNoneLoading: true,
		// 	refreshColor: '#000000',
		// 	refreshDiy: false,
		// 	isloaded: false,
		// 	list: [
        //         { id: 1, type: "个人智e通", name: "贵金属", phone: "15666667777" },
        //         { id: 2, type: "个人智e通", name: "贵金属", phone: "15666667777" },
        //         { id: 3, type: "个人智e通", name: "贵金属", phone: "15666667777" },
        //         { id: 4, type: "个人智e通", name: "贵金属", phone: "15666667777" },
        //     ]
        // },
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.getUserInfo();
        this.getReportConfigList(1,'perBusiList');
        // this.getReportConfigList(2,'cardBusiList');
        this.getReportConfigList(3,'pubBusiList');
        this.getReportConfigList(4,'othBusiList');

        this.getDictionaryInfo('ecard_business_reporting_sort');
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },
    // 获取当前登录者的用户信息
    getUserInfo(e) {        
        request({
            url: "/user/getUserInfo",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {}
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    userInfo: res.data.userInfo
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 获取字典
     */
    getReportConfigList(busiType,keyName) {
        request({
            url: "/busi/reportConfig/getReportConfigList",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
				dictType: "ecard_business_reporting_sort",
				busiType
			}
        }).then(res => {
            console.log(res)
            if(res.code == 0){
                if(busiType == 1){
                    this.setData({
                        [keyName]: res.data.concat([{
                            id: "h01",
                            busiName: "绑卡业务"
                        }])
                    })
                }else{
                    this.setData({
                        [keyName]: res.data
                    })
                }
            }
        }).catch(error => {
            // console.log(error)
        })     
    },
    /**
     * 获取字典
     */
    getDictionaryInfo(dictType) {
        request({
            url: "/commonApi/getDictionaryInfo",
            method: "GET",
            data: {
                dictType
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    ['dict.'+dictType]: res.data
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /** 分类点击事件*/
    tabChange(e) {
        let { index } = e.currentTarget.dataset;
        this.setData({
            activeIndex: index
        })
        // this.resetData();
        this.getData();
    },
    /**
     * 获取数据
     */
    getData() {
        let { activeIndex } = this.data;
        switch(activeIndex){
            case 0:
                
                break;
            case 1: 
                this.getMyBusiReportList();
                break;
            case 2: 
                
                break;
            default: 
                break;
        }
    },

    /**
     * 输入框输入时
     */
    input(e){
        let key = e.target.dataset.key;
        this.setData({
            ['params.'+key]: e.detail.value,
            // isFilter: !!e.detail.value,
        })
    },
    // 搜索
    searchConfirm(e){
        console.log(e.detail.value)
        this.setData({
            'params.busiName': e.detail.value
        })
        this.getData();
    },
    bindTypeChange(e){
        this.setData({
            typeIndex: e.detail.value,
            'params.busiType': this.data.dict.ecard_business_reporting_sort[e.detail.value].dictValue
        })
        this.getData();
    },
    /**
     * 日期选择
     */
    bindDateChange: function(e) {
        let { key } = e.currentTarget.dataset;
        this.setData({
            ['params.'+key]: e.detail.value
        })
    },
    searchBtn(e){
        this.getData();
    },
    /** 点击跳转个人填报 */
    toPersonalreporting(e) {
        let { item } = e.currentTarget.dataset;
        if(item.id != "h01"){
            wx.navigateTo({
                url: `/manager/pages/personalreporting/index?name=${item.busiName}&id=${item.id}&code=${item.busiCode}`,
            })
        }else{
            wx.navigateTo({
                url: `/manager/pages/bindcardreporting/index?name=${item.busiName}`,
            })
        }
    },
    /** 点击跳转绑卡填报 */
    // toBindcardreporting(e) {
    //     let { item } = e.currentTarget.dataset;
    //     wx.navigateTo({
    //         url: `/manager/pages/bindcardreporting/index?label=${item.busiName}&value=${item.id}`,
    //     })
    // },
    /** 点击跳转对公填报 */
    toCorporatereporting(e) {
        let { item } = e.currentTarget.dataset;
        wx.navigateTo({
          url: `/manager/pages/corporatereporting/index?name=${item.busiName}&id=${item.id}&code=${item.busiCode}`,
        })
    },
    /** 点击跳转其他填报 */
    toOtherreporting(e) {
        let { item } = e.currentTarget.dataset;
        wx.navigateTo({
          url: `/manager/pages/otherreporting/index?name=${item.busiName}&id=${item.id}&code=${item.busiCode}`,
        })
    },


    /**
     * 重置下拉
     */
    // resetScroller(){
    //     let scroller = {
	// 		pageNum: 0,
	// 		pageSize: 10,
	// 		totalPage: 10,
	// 		isNoneLoading: true,
	// 		refreshColor: '#000000',
	// 		refreshDiy: false,
	// 		isloaded: false,
	// 		list: []
	// 	}
	// 	this.setData({
    //         scroller,
	// 	})
    // },
    // refresh() {
    //     this.resetScroller()
    //     this.getData()
    // },
    
	// loadMore() {
    //     console.log("loadMore")
	// 	this.getData()
    // },

    /**
     * 获取填报记录
     */
    getMyBusiReportList() {
		// let { scroller } = this.data;
        // scroller.pageNum = scroller.pageNum + 1;
        // if(scroller.pageNum>scroller.totalPage){
        //     return
        // }
        request({
            url: `/busi/reportConfig/getMyBusiReportList`,
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                ...this.data.params,
                // pageNum: this.data.scroller.pageNum,
                // pageSize: this.data.scroller.pageSize,
            }
        }).then(res => {
            if(res.code == 0){
                // scroller.totalPage = Math.ceil(res.total/scroller.pageSize);
                // if(scroller.pageNum>=scroller.totalPage){
                //     scroller.isNoneLoading = false;
                // }
                // if(res.data.length>0){
                //     res.data.map(item => {
                //         item.creationTime = util.formatTime(new Date(item.creationTime));
                //         item.lastVisitDate = item.lastVisitDate?util.formatTime(new Date(item.lastVisitDate)):"";
                //         return item
                //     })
                // }
                // if(scroller.pageNum == 1){
                //     scroller.list = res.data;
                // }else{
                //     scroller.list = scroller.list.concat(res.data);
                // }
                // this.setData({
                //     scroller
                // })
                // let list = res.data || [];
                // list.map(item => {
                //     item.creationTime = util.formatDate(new Date(item.creationTime))
                //     return item
                // })
                
                this.setData({
                    list: res.data || []
                })
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    /**
     * 填报记录详情
     */
    toPerformancedesc(e){
        let { code } = e.currentTarget.dataset;
        wx.navigateTo({
          url: `/manager/pages/performancedesc/index?busiType=${this.data.params.busiType}&busiCode=${code}`,
        })
    }
})